<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
  <head>
  	<meta charset="utf-8">
    <title>短信发送历史详情</title>
	<%@ include file="/page/common/common.jsp" %>	
	<%@ include file="/page/common/bootstrap.jsp" %>
	
    <script type="text/javascript">
    	$(function(){
				
			
		});
    	
    	/** 发送短信 */
    	function sendSms(){
    		var telphone="";
    		var smsContent=$("#smsContent").val();
    		var remark=$("#remark").val();
    		if($("#togglePhone").attr("checked")=="checked"){
    			telphone=$.trim($("#telphone").val());
    			if(telphone==""){
    				alert("请输入电话号码");
    				return;
    			}
    			if(!isMobile(telphone)){
    				alert("请输入合法的电话号码");
    				return;
    			}
    		}
    		if(smsContent==""){
    			alert("请输入短信内容");
    			return;
    		}
    		
    		var data={
    			smsHistoryId:'${smsHistory.smsHistoryId}',
    			telphone:telphone,
    			smsContent:smsContent,
    			remark:remark
    		}   		
    		
    		$.messager.progress({
    			title:"发送短信",
    			msg:"正在发送短信，请稍后...",
    			text:"",
    			interval:200
    		}); 
    		$.post('${ctx}/sys/smshistory/reSendSms.sys',data,function(data){
    				$.messager.progress('close');
	        		if(data.success){//操作成功
						$.messager.alert('提示','发送完成，你可以到发送历史列表中查看','info',function(){
							location.href="${ctx}/sys/smshistory/queryDetail.sys?smsHistoryId="+data.data;
						});
					}else{
						$.messager.alert('提示',data.msg,'warning');	
					}
	        	});
    	}
    	
    	/** 终止短信 */
    	function stopSms(){
    		var smsHistoryId="${smsHistory.smsHistoryId}";
    		var remark=$("#remark").val();
    		
    		var data={
    			smsHistoryId:smsHistoryId,
    			remark:remark
    		};
    		
    		$.post('${ctx}/sys/smshistory/stopSms.sys',data,function(data){
    				$.messager.progress('close');
	        		if(data.success){//操作成功
						$.messager.alert('提示','操作成功!','info',function(){
							location.reload();//重载当前页面
						});	
					}else{
						$.messager.alert('提示',data.msg,'warning');	
					}
	        	});
    	}
    	
    	/** 更换手机号码 */
    	function toggleTelphone(){
    		if($("#togglePhone").attr("checked")=="checked"){
    			$("#telphone").removeAttr("disabled");
    		}else{
    			$("#telphone").attr("disabled","disabled");
    		}
    	}
	</script>	
  </head>
  
  <body>
	  <div class="container">
	  	
	  		<h4 class="htitle">旅客基本信息</h4>
	  		<div class="well">
		  		<div class="media">
					<div class="media-body">
						<h5>旅客姓名：${pass.passName}</h5>
						<table class="table table-bordered" style="background-color: #fff;">
							<tbody>
								<tr>
									<td style="text-align: right;">票号：</td>
									<td>${pass.tktNo}</td>
									<td style="text-align: right;">航班号：</td>
									<td>${pass.flightNo}</td>
									<td style="text-align: right;">航段：</td>
									<td>${pass.segment}</td>
								</tr>
								<tr>
									<td style="text-align: right;">航班日期：</td>
									<td>
									<c:forEach items="${pass.flightDates}" var="flightDate">
										${flightDate}<br/>
									</c:forEach>
									</td>
									<td style="text-align: right;">起飞时间：</td>
									<td>
									<c:forEach items="${pass.flightTimes}" var="flightTime">
										${flightTime}<br/>
									</c:forEach>
									</td>
									<td style="text-align: right;">手机号码：</td>
									<td>${pass.telphone}</td>
								</tr>
							</tbody>
						</table>
		    		</div>
		   		</div>
	  		</div>
    	
    		<h4 class="htitle">发送历史</h4>
    		<div class="well">
    			<table class="table">
    				<thead>
    					<tr>
    						<th>#</th>
    						<th>操作人</th>
    						<th>操作时间</th>
    						<th>操作</th>
    						<th>备注</th>
    					</tr>
    				</thead>
    				<tbody>
    					<c:forEach items="${smsOpralist}" var="smsOpra" varStatus="s">
    					<tr>
    						<td>${s.count}</td>
    						<td>${smsOpra.opraName}</td>
    						<td><fmt:formatDate value="${smsOpra.opraTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
    						<td>
    						<c:choose>
    						<c:when test="${smsOpra.opraType==0}">
    							<span class="label label-info">首次发送</span>
    						</c:when>
    						<c:when test="${smsOpra.opraType==1}">
    							<span class="label label-important">重新发送</span>
    						</c:when>
    						<c:when test="${smsOpra.opraType==2}">
    							<span class="label label-warning">终止发送</span>
    						</c:when>
    						<c:otherwise>
    							<span class="label label-inverse">未知</span>
    						</c:otherwise>
    						</c:choose>
    						</td>
    						<td>${smsOpra.remark}</td>
    					</tr>
    					</c:forEach>
    				</tbody>
    			</table>
    		</div>
    		<h4 class="htitle">重新发送</h4>
    		<div class="well">
    			<form class="form-inline" id="smsForm" action="send_msg.jsp">
    				<div class="control-group">
    					<label style="margin-left: 16px;">当前状态：</label>
    					<c:choose>
    					<c:when test="${smsHistory.status==0}">
    						<span class="badge badge-info">正在发送</span>
    					</c:when>
    					<c:when test="${smsHistory.status==1}">
    						<span class="badge badge-success">发送成功</span>
    					</c:when>
    					<c:when test="${smsHistory.status==2}">
    						<span class="badge badge-important">发送失败</span>
    					</c:when>
    					<c:when test="${smsHistory.status==3}">
    						<span class="badge badge-inverse">发送终止</span>
    					</c:when>
    					</c:choose>
    					
    				</div>
    				<div class="control-group">
	    				 <label class="checkbox">
							<input type="checkbox" onclick="toggleTelphone();" id="togglePhone"> 更换号码：
						 </label>
						 <input type="text" name="telphone" id="telphone" disabled="disabled">
	    				 
					 </div>
					 <!-- 
					 <div class="control-group">
					 	<label class="checkbox">
							<input type="checkbox"> 使用模版：
						 </label>
						 <select name="template" id="template">
				   	 	  <option>选择模版</option>
						  <option>出票通知短信模版A</option>
						  <option>出票通知短信模版B</option>
					 	</select>	
					 </div>
					 -->
				    <div class="control-group">
				    	<label style="margin-left: 16px;">编辑短信：</label>
					   
					    <div class="controls">
					   		<textarea rows="5" class="span8 limitNum" charnum="300" id="smsContent">${smsHistory.smsContent}</textarea> 		   	 	
					    </div>
					</div>
					 <div class="control-group">
				    	<label style="margin-left: 16px;">操作备注：</label>
					   
					    <div class="controls">
					   		<textarea rows="3" class="span8" id="remark" placeholder="请输入备注信息"></textarea> 		   	 	
					    </div>
					</div>
					<div class="control-group">
						<div class="controls">
							<c:if test="${smsHistory.status==constant.SMS_SEND_ING or smsHistory.status==constant.SMS_SEND_FAIL}">
							<button type="button" class="btn btn-info" onclick="sendSms();"><i class="icon-white icon-repeat"></i>重新发送</button>
							</c:if>
							<c:if test="${smsHistory.status==constant.SMS_SEND_FAIL}">
							<button type="button" class="btn btn-danger" onclick="stopSms();"><i class="icon-white icon-stop"></i>终止发送</button>
							</c:if>
							<button type="button" class="btn" onclick="location.reload();"><i class="icon-refresh"></i>刷新</button>
						</div>
					</div>	    		    
				</form>
    		</div>
	    </div><!-- end container -->	 
  </body>
</html>
